package com.atguigu.jvm.chap06;

import java.util.concurrent.TimeUnit;

public class StrongReferenceTest {

    public static void main(String[] args) {
        // 定义强引用
        User user = new User(1, "zhangsan");
        // 定义强引用
        User user1 = user;

        // 设置user为null，User对象不会被回收，因为依然被user1引用
        user = null;

        // 强制垃圾回收
        System.gc();

         try {
             TimeUnit.SECONDS.sleep(1);
         } catch (InterruptedException e) {
             throw new RuntimeException(e);
         }
        System.out.println(user1);
    }
}